/**
 * 利用js内置api sort
*/

const majorityElement = nums => {
    nums.sort((a, b) => a - b)
    return nums[parseInt(nums.length / 2)]
}

console.log(majorityElement([3, 2, 3, 1, 1, 2, 2]));